<script type="text/javascript">
$(function(){
	var pg = App.batch.monitorIndex.ui, pp = pg.params;
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols: [{
			field: 'name', title: '批量名称', width: 240
		},{
			field: 'type', title: '类型', width: 60,
			render: function(r){
				return Cache.batch.execution.type[r.type];
			}
		},{
			field: 'addr', title: '执行节点', width: 120
		},{
			field: 'startTime', title: '开始时间', width: 160
		},{
			field: 'endTime', title: '结束时间', width: 160
		},{
			field: 'status', title: '进度与状态', width: 120,
			render: function(r){
				return Cache.batch.execution.status[r.status];
			}
		},{
			field: 'id', title : '操作', width: 100,
			render: function(r, tr, gd) {
				var p = $('<div></div>'), v = r.status,
					st = '<span class="a"></span>';
				//只有失败4、挂起5或中断7的任务组执行才可以续跑
				if (App.logon.power('batch.execution.resume')
					&& (v == 4 || v == 5 || v == 7)) {
					$(st).click(function(){
						$.post(App.ctx + '/dispatcher/resume.do', {
							id: r.id,
						}, function(rs){
							gd.load();
						});
					}).append('续跑').appendTo(p);
					p.append('&nbsp;');
				}
				//只有成功3、失败4、挂起5或中断7的批量任务才可以重跑
				if (App.logon.power('batch.execution.redo')
					&& (v == 3 || v == 4 || v == 5 || v == 7)) {
					$(st).click(function(){
						$.post(App.ctx + '/dispatcher/redo.do', {
							id: r.id,
						}, function(rs){
							gd.load();
						});
					}).append('重跑').appendTo(p);
					p.append('&nbsp;');
				}
				//只有初始0、排队1或执行2的任务组执行才可以取消
				if (App.logon.power('batch.execution.cancel')
					&& (v == 0 || v == 1 || v == 2)) {
					$(st).click(function(){
						$.post(App.ctx + '/dispatcher/cancel.do', {
							id: r.id,
						}, function(rs){
							gd.load();
						});
					}).append('取消').appendTo(p);
					p.append('&nbsp;');
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/execution/executing.do',
			params: {
				pageNo: 1, pageSize: 20
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13) {
			gd.load({ key : $(this).val() });
		}
	});
	pg.seek('refresh').click(function(){
		gd.load();
	});
	
	function adjust(){
		var p = pg.parent(), w = p.width(), h = p.height();
		pg.width(w - 64);
		gd.parent().height(h - 96);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="navi">
	<span class="a" name="back">批量监控</span>&gt;&gt;
	<span name="title"></span>&nbsp;正在执行
</div>
<div class="head">
	<button name="refresh">手动刷新</button>
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="key" placeholder="查找" />
</div>
<div class="body">
	<div class="grid"></div>
</div>